using System;
using System.Collections.Generic;
using System.Text;
using DataTools;
using DataTools.PagingUtils;
using ObjectLayer;

namespace CommonAccessLayer
{
	public class religiousDAO
{
		public static List<religiousBO> GetAll()
		{
			return CBO.FillCollection<religiousBO>(DataProvider.getInstance().getAll(TableName.religious, PagingHelper.CreateOrder(new OrderObject(religiousTable.id, SortOrder.Desc))));
		}
		static object _Clock = new object();
		public static List<religiousBO> GetAllC()
		{
			List<religiousBO> list = new List<religiousBO>();
			if(DataCache.GetCache(CacheName.religious) == null)
			{
				lock (_Clock)
				{
					if (DataCache.GetCache(CacheName.religious) != null)
					{
						list = (List<religiousBO>)DataCache.GetCache(CacheName.religious);
					}
					else
					{
			list = CBO.FillCollection<religiousBO>(DataProvider.getInstance().getAll(TableName.religious, PagingHelper.CreateOrder(new OrderObject(religiousTable.id, SortOrder.Desc))));
						DataCache.SetCache(CacheName.religious, list);
					}
				}
			}
			else
			{
					list = (List<religiousBO>)DataCache.GetCache(CacheName.religious);
			}
		return list;
		}
		public static int InsertUpdateDelete(religiousBO religious, ProviderAction action)
		{
			int rs = DataProvider.getInstance().InsertUpdateDelete(action, StoreProcedureName.InsertUpdateDelete_religious, "@" + religiousTable.id, religious.id,religious.name, DataTools.ConvertType.ToInt(action));
			if (rs != -1)
			{
				DataCache.RemoveCache(CacheName.religious);
			}
			return rs;
		}
		public static int Insert(religiousBO religious)
		{
			 return InsertUpdateDelete(religious, ProviderAction.Insert);
		}
		public static int Update(religiousBO religious)
		{
			 return InsertUpdateDelete(religious, ProviderAction.Update);
		}
		public static int Delete(religiousBO religious)
		{
			 return InsertUpdateDelete(religious, ProviderAction.Delete);
		}
		public static int Delete(int id)
		{
			religiousBO religious = new religiousBO(id);
			return Delete(religious);
		}
	}
}